#include<bits/stdc++.h>
using namespace std;
long long f[200005][2], a[200005], n;
int main() {
    cin >> n;
    f[0][0] = -1e15;
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
        f[i][0] = max(f[i - 1][0], f[i - 1][1] + a[i]);
        f[i][1] = max(f[i - 1][1], f[i - 1][0] + 2 * a[i]);
    }
    cout << max(f[n][0], f[n][1]);
    return 0;
}